package com.amarsoft.are.lang;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Properties;

public class StringX
{
  public static Date parseDate(String paramString)
  {
    if (paramString == null)
      return null;
    Date localDate = null;
    String str = null;
    char[] arrayOfChar = { '/', '-', '.' };
    if (paramString.length() < 8)
      return localDate;
    if (paramString.length() > 10)
      paramString = paramString.substring(0, 10);
    for (int i = 0; i < arrayOfChar.length; ++i)
    {
      int j = paramString.indexOf(arrayOfChar[i]);
      if (j < 0)
        continue;
      if (j == 4)
      {
        str = "yyyy" + arrayOfChar[i] + "M" + arrayOfChar[i] + "d";
        break;
      }
      if (j < 4)
      {
        str = "M" + arrayOfChar[i] + "d" + arrayOfChar[i] + "y";
        break;
      }
      return null;
    }
    if (str == null)
      if (paramString.substring(0, 2).compareTo("12") > 0)
        str = "yyyyMMdd";
      else
        str = "MMddyyyy";
    SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat(str);
    try
    {
      localDate = localSimpleDateFormat.parse(paramString);
    }
    catch (ParseException localParseException)
    {
      localDate = null;
    }
    return localDate;
  }

  public static boolean parseBoolean(String paramString)
  {
    return (paramString != null);
  }

  public static String[] parseArray(String paramString)
  {
    if (paramString == null)
      return null;
    ArrayList<String> localArrayList = new ArrayList<String>();
    int i = 0;
    int j = 0;
    int k = 0;
    int l = -1;
    while (k < paramString.length())
    {
      if (paramString.charAt(k) == '{')
      {
        if (++i == 1)
          l = k + 1;
      }
      else if ((paramString.charAt(k) == '}') && (++j == i))
      {
        localArrayList.add(paramString.substring(l, k));
        l = -1;
        i = 0;
        j = 0;
      }
      ++k;
    }
    return ((String[])localArrayList.toArray(new String[0]));
  }

  public static Properties parseProperties(String paramString)
  {
    Properties localProperties = new Properties();
    String[] arrayOfString = parseArray(paramString);
    if ((arrayOfString != null) && (arrayOfString.length > 0))
      for (int i = 0; i < arrayOfString.length; ++i)
      {
        int j = arrayOfString[i].indexOf(61);
        if (j < 1)
          continue;
        if (j == arrayOfString[i].length())
          continue;
        String str1 = trimAll(arrayOfString[i].substring(0, j));
        if (str1 == "")
          continue;
        String str2 = arrayOfString[i].substring(j + 1);
        localProperties.setProperty(str1, str2);
      }
    return localProperties;
  }

  public static String bytesToHexString(byte[] paramArrayOfByte, boolean paramBoolean)
  {
    if (paramArrayOfByte == null)
      return null;
    StringBuffer localStringBuffer = new StringBuffer();
    for (int i = 0; i < paramArrayOfByte.length; ++i)
    {
      int j = paramArrayOfByte[i];
      localStringBuffer.append(Integer.toString(j >> 4 & 0xF, 16)).append(Integer.toString(j & 0xF, 16));
    }
    String str = localStringBuffer.toString();
    return ((paramBoolean) ? str.toUpperCase() : str.toLowerCase());
  }

  public static String trimStart(String paramString)
  {
    String str = null;
    int i = 0;
    if (paramString != null)
    {
      for (i = 0; i < paramString.length(); ++i)
        if (!(Character.isWhitespace(paramString.charAt(i))))
          break;
      str = (i < paramString.length()) ? paramString.substring(i) : "";
    }
    return str;
  }

  public static String trimEnd(String paramString)
  {
    String str = null;
    int i = 0;
    if (paramString != null)
    {
      for (i = paramString.length() - 1; i >= 0; --i)
        if (!(Character.isWhitespace(paramString.charAt(i))))
          break;
      str = (i >= 0) ? paramString.substring(0, i + 1) : "";
    }
    return str;
  }

  public static String trimAll(String paramString)
  {
    String str = null;
    if (paramString != null)
      str = trimEnd(trimStart(paramString));
    return str;
  }

  public static boolean isEmpty(String paramString)
  {
    return ((paramString == null) || (paramString.equals("")));
  }

  public static boolean isSpace(String paramString)
  {
    if (paramString == null)
      return true;
    int i = 1;
    for (int j = 0; j < paramString.length(); ++j)
    {
      if (Character.isSpaceChar(paramString.charAt(j)))
        continue;
      i = 0;
      break;
    }
    return i==1?true:false;
  }

  public static boolean isEmpty(DataElement paramDataElement)
  {
    return ((paramDataElement == null) || (paramDataElement.isNull()) || (isEmpty(paramDataElement.getString())));
  }

  public static boolean isSpace(DataElement paramDataElement)
  {
    return ((isEmpty(paramDataElement)) || (isSpace(paramDataElement.getString())));
  }
}